package org.agbe.perdu;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

	private Context context = this;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		construirePage();
	}

	private void construirePage() {
		TextView tv = (TextView) findViewById(R.id.textView1);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < 3000; i++) {
			sb.append("Et voici la ligne numéro " + i);
		}
		tv.setText(sb.toString());
		Button b = (Button) findViewById(R.id.button1);
		b.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				final Dialog dialog = new Dialog(MainActivity.this.context);
				dialog.setContentView(R.layout.custom);
				dialog.setTitle("Title...");

				// set the custom dialog components - text, image and button
				TextView text = (TextView) dialog.findViewById(R.id.text);
				text.setText("Android custom dialog example!");
				ImageView image = (ImageView) dialog.findViewById(R.id.image);
				image.setImageResource(R.drawable.ic_launcher);

				Button dialogButton = (Button) dialog
						.findViewById(R.id.dialogButtonOK);
				// if button is clicked, close the custom dialog
				dialogButton.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						dialog.dismiss();
					}
				});

				dialog.show();
			}
		});
	}

	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.load_game:
			Toast.makeText(this, "Charger la partie", Toast.LENGTH_SHORT)
					.show();
			return true;
		case R.id.new_game:
			Toast.makeText(this, "Nouvelle partie", Toast.LENGTH_SHORT).show();
			return true;
		case R.id.save_game:
			Toast.makeText(this, "Sauvegarder la partie", Toast.LENGTH_SHORT)
					.show();
			return true;
		case R.id.quit_game:
			// Pour fermer l'application il suffit de faire finish()
			finish();
			return true;
		}
		return false;
	}

}
